library(rstan)
library(survival)
library(tidyverse)
library(tidybayes)
# data, parameters, model and generated quantities blocks
Stan_exponential_survival_model <- "
data{
  int <lower=1> N_uncensored;
  int <lower=1> N_censored;
  int <lower=0> numCovariates;
  matrix[N_censored, numCovariates] X_censored;
  matrix[N_uncensored, numCovariates] X_uncensored;
  vector <lower=0>[N_censored] times_censored;
  vector <lower=0>[N_uncensored] times_uncensored;
}

parameters{
  vector[numCovariates] beta; //regression coefficients
  real alpha; //intercept
}

model{
  beta ~ normal(0,10); //prior on regression coefficients
  alpha ~ normal(0,10); //prior on intercept
  target += exponential_lpdf(times_uncensored | exp(alpha+X_uncensored * beta)); //log-likelihood part for uncensored times
  target += exponential_lccdf(times_censored | exp(alpha+X_censored * beta)); //log-likelihood for censored times
}

generated quantities{
  vector[N_uncensored] times_uncensored_sampled; //prediction of death
  for(i in 1:N_uncensored) {
    times_uncensored_sampled[i] = exponential_rng(exp(alpha+X_uncensored[i,]* beta));
  }
}
"
# prepare the data
set.seed(42); 
require (tidyverse);
data <- read_csv('../data.csv')
N <- nrow (data);
data$developers_count <- car::recode(data$author_count, "0:20 = 0; 21:max(data$author_count) = 1")
X <- as.matrix(pull(data, developers_count)); 
is_censored <- pull(data, status)==0; 
times <- pull(data, duration); 
msk_censored <- is_censored == 1; 
N_censored <- sum(msk_censored);
# put data into a list for Stan
Stan_data <- list (N_uncensored = N - N_censored, 
                    N_censored = N_censored,
                    numCovariates = ncol(X), 
                    X_censored = as.matrix(X[msk_censored,]),
                    X_uncensored = as.matrix(X[!msk_censored ,]), 
                    times_censored = times[msk_censored],
                    times_uncensored = times[!msk_censored])
# fit Stan model
require(rstan)
exp_surv_model_fit <- suppressMessages(stan(model_code = Stan_exponential_survival_model, data = Stan_data))
Warning in system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  error in running command
clang: error: no input files

SAMPLING FOR MODEL 'bf5dbbde6a245330de71a285e3fe7c42' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 0.000472 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 4.72 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 1: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 1: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 1: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 1: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 1: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 1: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 1: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 1: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 1: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 1: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 1: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 1: 
Chain 1:  Elapsed Time: 0.920697 seconds (Warm-up)
Chain 1:                0.965172 seconds (Sampling)
Chain 1:                1.88587 seconds (Total)
Chain 1: 

SAMPLING FOR MODEL 'bf5dbbde6a245330de71a285e3fe7c42' NOW (CHAIN 2).
Chain 2: 
Chain 2: Gradient evaluation took 0.000164 seconds
Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 1.64 seconds.
Chain 2: Adjust your expectations accordingly!
Chain 2: 
Chain 2: 
Chain 2: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 2: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 2: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 2: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 2: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 2: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 2: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 2: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 2: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 2: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 2: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 2: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 2: 
Chain 2:  Elapsed Time: 0.952962 seconds (Warm-up)
Chain 2:                0.946664 seconds (Sampling)
Chain 2:                1.89963 seconds (Total)
Chain 2: 

SAMPLING FOR MODEL 'bf5dbbde6a245330de71a285e3fe7c42' NOW (CHAIN 3).
Chain 3: 
Chain 3: Gradient evaluation took 0.00017 seconds
Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 1.7 seconds.
Chain 3: Adjust your expectations accordingly!
Chain 3: 
Chain 3: 
Chain 3: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 3: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 3: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 3: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 3: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 3: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 3: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 3: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 3: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 3: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 3: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 3: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 3: 
Chain 3:  Elapsed Time: 0.939159 seconds (Warm-up)
Chain 3:                0.949951 seconds (Sampling)
Chain 3:                1.88911 seconds (Total)
Chain 3: 

SAMPLING FOR MODEL 'bf5dbbde6a245330de71a285e3fe7c42' NOW (CHAIN 4).
Chain 4: 
Chain 4: Gradient evaluation took 0.000166 seconds
Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 1.66 seconds.
Chain 4: Adjust your expectations accordingly!
Chain 4: 
Chain 4: 
Chain 4: Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 4: Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 4: Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 4: Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 4: Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 4: Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 4: Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 4: Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 4: Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 4: Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 4: Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 4: Iteration: 2000 / 2000 [100%]  (Sampling)
Chain 4: 
Chain 4:  Elapsed Time: 0.934158 seconds (Warm-up)
Chain 4:                0.872527 seconds (Sampling)
Chain 4:                1.80669 seconds (Total)
Chain 4: 
# print model fit
print(get_seed(exp_surv_model_fit))
[1] 1781592037
# print fit summary
fit_summary <- summary(exp_surv_model_fit)
print(fit_summary$summary)
                                      mean      se_mean           sd         2.5%          25%          50%
beta[1]                          -1.409013 0.0026280208   0.13244960    -1.677495    -1.499322    -1.407036
alpha                            -4.738585 0.0008769689   0.04167914    -4.822669    -4.765333    -4.738450
times_uncensored_sampled[1]     114.748918 1.8370043338 114.24553835     3.157978    31.876633    76.836579
times_uncensored_sampled[2]     119.865441 1.8379226178 117.43843959     3.571390    35.665890    83.166967
times_uncensored_sampled[3]     114.511160 1.9103783650 112.92657636     3.537449    33.433981    80.070856
times_uncensored_sampled[4]     113.960292 1.8331149051 116.99752908     2.687777    31.881852    77.989772
times_uncensored_sampled[5]     114.438091 1.8524776854 116.51590842     3.163008    32.870728    77.891142
times_uncensored_sampled[6]     114.628263 1.8511767299 115.03248139     2.791244    35.039902    80.157283
times_uncensored_sampled[7]     114.634797 1.7822040061 111.80496164     3.209696    33.836658    81.646803
times_uncensored_sampled[8]     110.606231 1.6767670944 107.79497976     3.101947    32.820210    78.275663
times_uncensored_sampled[9]     114.836614 1.7926905642 114.89542649     2.808582    33.518333    79.299587
times_uncensored_sampled[10]    113.374099 1.8266588379 115.56884273     2.886520    32.800476    77.755367
times_uncensored_sampled[11]    113.650335 1.7888860391 112.78069369     3.046404    32.286506    80.616718
times_uncensored_sampled[12]    113.605358 1.7908974361 116.28187003     3.247074    32.807655    78.403829
times_uncensored_sampled[13]    116.885793 1.7902936016 116.50220590     3.193254    34.317733    80.569119
times_uncensored_sampled[14]    112.367649 1.7155222095 109.24625490     2.801732    32.487841    78.494594
times_uncensored_sampled[15]    112.637915 1.9671525712 116.88261677     2.904535    30.670703    76.125703
times_uncensored_sampled[16]    111.991202 1.8093068784 112.77116368     2.656018    32.678008    78.227254
times_uncensored_sampled[17]    115.036033 1.7812775852 112.39681743     2.883118    32.394891    81.988009
times_uncensored_sampled[18]    113.199662 1.8067192031 111.46896149     2.457262    32.658051    80.556648
times_uncensored_sampled[19]    111.807403 1.7351302103 111.10011613     2.489032    30.948792    77.335706
times_uncensored_sampled[20]    119.066032 1.8371080315 114.26181989     3.160901    36.503804    84.326699
times_uncensored_sampled[21]    115.696864 1.9758857408 119.01287876     2.702289    33.067590    77.401768
times_uncensored_sampled[22]    113.072576 1.7118997946 112.37001665     3.211566    32.877209    76.891102
times_uncensored_sampled[23]    112.545454 1.7396843989 109.46249129     2.611059    31.865179    78.433535
times_uncensored_sampled[24]    113.519407 1.8045931228 112.94733037     3.125745    32.495333    78.559896
times_uncensored_sampled[25]    116.017984 1.8373704882 115.70073992     2.760987    34.150191    80.633314
times_uncensored_sampled[26]    111.345324 1.8150472209 115.15333194     3.239513    32.234860    74.725288
times_uncensored_sampled[27]    115.067006 1.8534282649 116.71002304     3.008279    33.029258    80.119160
times_uncensored_sampled[28]    112.837641 1.8157135006 115.08937341     3.206752    32.336684    77.579044
times_uncensored_sampled[29]    114.328866 1.8161426626 111.29027111     2.975488    31.859426    80.719429
times_uncensored_sampled[30]    116.210934 1.8510548563 117.15572273     3.336195    33.383577    80.922439
times_uncensored_sampled[31]    117.164604 1.8987946608 118.63332578     2.847351    33.346237    81.038764
times_uncensored_sampled[32]    112.180731 1.8291462698 111.72743728     2.399076    32.417590    76.258349
times_uncensored_sampled[33]    113.502459 1.7412820191 112.78171457     2.789170    31.496763    77.094567
times_uncensored_sampled[34]    114.513119 1.8190764347 113.52550330     3.081498    34.088632    79.732524
times_uncensored_sampled[35]    116.141382 1.8729361156 115.58879329     2.839435    33.399207    80.156472
times_uncensored_sampled[36]    114.248707 1.7817820953 112.43379696     3.093695    34.370537    80.577117
times_uncensored_sampled[37]    114.839766 1.7746807041 114.26923422     3.184977    33.874242    80.362571
times_uncensored_sampled[38]    115.303432 1.8742301174 116.43443953     3.043613    32.357545    79.398164
times_uncensored_sampled[39]    113.611277 1.8354823534 114.79333078     3.209168    32.626455    79.704459
times_uncensored_sampled[40]    116.273554 1.9222867626 116.04661457     2.596509    32.898826    81.283702
times_uncensored_sampled[41]    117.081689 1.7991216989 112.21660644     3.127863    34.317099    80.619777
times_uncensored_sampled[42]    114.885094 1.9123095363 116.33872129     2.783404    33.055964    79.394374
times_uncensored_sampled[43]    112.496903 1.8379038459 114.85942044     3.338855    32.566303    77.496419
times_uncensored_sampled[44]    116.330856 1.8577357792 118.21266116     3.273292    34.345987    81.061137
times_uncensored_sampled[45]    111.921883 1.7198429977 110.62277201     2.913107    32.704207    78.881405
times_uncensored_sampled[46]    112.951387 1.7684061510 111.29148458     3.374646    32.974034    76.293381
times_uncensored_sampled[47]    116.616029 1.8688805617 121.73772937     3.232953    32.673380    80.422343
times_uncensored_sampled[48]    114.349361 1.7704416009 111.30909589     2.955325    33.099032    81.390648
times_uncensored_sampled[49]    115.694868 2.0118086481 115.70698248     2.409178    31.581084    79.111714
times_uncensored_sampled[50]    113.620053 1.8529501133 112.88083323     2.870059    33.275285    79.281213
times_uncensored_sampled[51]    113.830507 1.9358051845 112.16312600     2.901751    33.865021    80.014333
times_uncensored_sampled[52]    117.499550 1.9307093110 117.20545205     3.045203    33.478916    82.485439
times_uncensored_sampled[53]    112.841261 1.7730325398 110.65521692     3.152006    33.461911    79.205780
times_uncensored_sampled[54]    113.770263 1.7927570773 112.76609155     2.958088    32.097371    81.286467
times_uncensored_sampled[55]    115.087694 1.9499257245 118.45164434     2.871020    32.748280    79.074054
times_uncensored_sampled[56]    115.256435 1.9183405284 119.32777353     2.645240    33.439652    79.620046
times_uncensored_sampled[57]    110.818768 1.7229284971 112.63390725     2.408834    31.008527    76.493712
times_uncensored_sampled[58]    116.751737 1.8823064685 114.57534101     2.898587    34.081322    81.536092
times_uncensored_sampled[59]    114.838068 1.7914457486 113.87210869     2.721862    33.514224    81.228918
times_uncensored_sampled[60]    110.787377 1.7616616364 110.82112086     2.525288    32.042694    75.887113
times_uncensored_sampled[61]    112.846216 1.7268667727 111.99672049     2.860086    33.148614    80.330559
times_uncensored_sampled[62]    116.196793 1.8465551029 114.21964823     2.851707    34.390556    82.242353
times_uncensored_sampled[63]    114.114096 1.9166559807 114.04289796     2.759633    32.665407    80.243188
times_uncensored_sampled[64]    113.550064 1.8477042650 114.44566909     3.082074    32.732179    77.931989
times_uncensored_sampled[65]    114.246548 1.7962678453 114.96550863     3.188175    33.119244    79.080655
times_uncensored_sampled[66]    115.290633 1.8533791532 116.23156945     2.599775    33.664838    80.311284
times_uncensored_sampled[67]    115.504903 1.9369595901 118.26002266     3.430321    33.294991    79.524425
times_uncensored_sampled[68]    111.489103 1.8784207601 112.71648672     2.817025    31.867836    77.741179
times_uncensored_sampled[69]    113.191050 1.8159800226 111.98480294     3.225945    31.964963    80.969177
times_uncensored_sampled[70]    115.554476 1.7956420413 112.67921679     3.076370    33.047239    81.694165
times_uncensored_sampled[71]    112.983805 1.8068753432 112.77091926     3.338408    32.676289    79.338673
times_uncensored_sampled[72]    115.506112 1.8769145405 117.18512252     2.252208    30.376360    78.980180
times_uncensored_sampled[73]    115.398797 1.9796057572 116.23832516     3.005857    33.468532    80.346736
times_uncensored_sampled[74]    109.918868 1.7051642733 107.50792456     2.949902    32.510887    76.199371
times_uncensored_sampled[75]    114.183092 1.7973451713 115.95461849     2.613565    30.972511    77.100017
times_uncensored_sampled[76]    114.062714 1.7543792564 111.36182178     3.054476    34.217594    81.975172
times_uncensored_sampled[77]    111.806553 1.7664186958 112.57146748     2.546246    31.098497    77.600707
times_uncensored_sampled[78]    112.849447 1.8645268688 113.73120645     2.737883    32.304376    77.442969
times_uncensored_sampled[79]    112.741887 1.7946539348 114.15292301     3.013043    31.388715    77.819219
times_uncensored_sampled[80]    114.972172 1.8574849528 117.18807319     2.730411    34.117928    77.868103
times_uncensored_sampled[81]    116.422871 1.8704127445 119.82535210     2.662810    32.629442    79.603660
times_uncensored_sampled[82]    116.236444 1.9198737208 115.82155172     3.116008    33.204788    81.434049
times_uncensored_sampled[83]    115.682078 1.9067892168 116.45700354     3.229578    31.772353    80.158096
times_uncensored_sampled[84]    112.305221 1.8168935255 115.42560133     2.958418    31.308990    77.253777
times_uncensored_sampled[85]    118.359469 1.8443093222 118.85027339     3.353921    34.622761    81.080658
times_uncensored_sampled[86]    113.225737 1.7950294700 113.76819578     2.982522    32.676024    77.795693
times_uncensored_sampled[87]    113.690106 1.7230729990 112.24052585     3.311051    32.623213    79.694352
times_uncensored_sampled[88]    114.606652 1.8802951255 117.18356931     2.677411    31.609498    79.107677
times_uncensored_sampled[89]    119.456848 1.8897919111 120.86510915     3.056804    33.842142    82.562988
times_uncensored_sampled[90]    116.988271 1.7762189696 113.77525447     3.037813    34.970472    81.579601
times_uncensored_sampled[91]    115.436560 1.8468780317 113.14308602     3.079217    32.988394    80.737918
times_uncensored_sampled[92]    114.174087 1.9226326089 117.09802221     2.240360    33.861011    77.040066
times_uncensored_sampled[93]    113.711126 1.7895902514 111.64884359     3.132940    32.562543    79.701842
times_uncensored_sampled[94]    115.020440 1.8849813063 115.97666086     3.392841    32.729919    80.576021
times_uncensored_sampled[95]    117.112566 1.8661266468 113.74886001     2.771792    33.810769    82.337642
times_uncensored_sampled[96]    113.786063 1.7479738540 111.63475308     3.534576    33.779504    80.012899
times_uncensored_sampled[97]    113.355202 1.8209458645 113.45630525     2.287952    33.033474    79.341863
times_uncensored_sampled[98]    114.531024 1.7806866689 115.70054445     3.174515    32.634186    79.026891
                                       75%        97.5%    n_eff      Rhat
beta[1]                          -1.317992    -1.156991 2540.059 1.0009225
alpha                            -4.711266    -4.656309 2258.755 1.0003625
times_uncensored_sampled[1]     161.955413   422.799805 3867.748 1.0002362
times_uncensored_sampled[2]     165.638005   440.759189 4082.875 0.9995951
times_uncensored_sampled[3]     159.952686   410.668972 3494.247 1.0010001
times_uncensored_sampled[4]     156.707210   427.803829 4073.559 0.9996277
times_uncensored_sampled[5]     157.047347   423.260615 3956.075 1.0000341
times_uncensored_sampled[6]     154.920048   428.631268 3861.404 0.9994373
times_uncensored_sampled[7]     160.090786   407.742986 3935.567 1.0003424
times_uncensored_sampled[8]     154.598463   401.535556 4132.868 0.9995167
times_uncensored_sampled[9]     161.194317   426.852117 4107.663 0.9993255
times_uncensored_sampled[10]    155.552764   419.340695 4002.825 1.0000438
times_uncensored_sampled[11]    158.273618   409.008339 3974.698 1.0001663
times_uncensored_sampled[12]    155.983423   420.910797 4215.825 0.9995505
times_uncensored_sampled[13]    161.772404   432.120385 4234.672 1.0003957
times_uncensored_sampled[14]    160.213421   399.431016 4055.276 0.9995332
times_uncensored_sampled[15]    151.760281   427.530819 3530.399 0.9999401
times_uncensored_sampled[16]    157.098266   408.721155 3884.827 1.0015108
times_uncensored_sampled[17]    161.602866   403.815203 3981.483 1.0000615
times_uncensored_sampled[18]    160.186091   397.066954 3806.507 1.0005329
times_uncensored_sampled[19]    158.019518   404.740151 4099.821 0.9999738
times_uncensored_sampled[20]    164.649094   425.521214 3868.413 1.0004050
times_uncensored_sampled[21]    159.540241   425.706796 3627.975 0.9998521
times_uncensored_sampled[22]    157.623206   422.771691 4308.680 0.9997726
times_uncensored_sampled[23]    161.231037   400.322760 3959.038 0.9993953
times_uncensored_sampled[24]    156.819426   414.522442 3917.359 1.0000359
times_uncensored_sampled[25]    159.894413   427.840280 3965.325 1.0007620
times_uncensored_sampled[26]    147.203480   430.097548 4025.105 1.0011261
times_uncensored_sampled[27]    157.813409   426.252452 3965.197 0.9994729
times_uncensored_sampled[28]    151.135519   416.785122 4017.684 0.9994477
times_uncensored_sampled[29]    162.580430   404.942695 3755.039 1.0001733
times_uncensored_sampled[30]    160.836048   420.937369 4005.792 0.9994989
times_uncensored_sampled[31]    161.353671   427.904564 3903.529 0.9999427
times_uncensored_sampled[32]    155.697074   427.122387 3730.979 1.0004681
times_uncensored_sampled[33]    162.244959   415.088666 4195.069 0.9995157
times_uncensored_sampled[34]    158.332089   420.749443 3894.798 1.0002163
times_uncensored_sampled[35]    161.042165   433.703813 3808.777 1.0000926
times_uncensored_sampled[36]    159.132189   414.163891 3981.847 1.0006859
times_uncensored_sampled[37]    160.181730   422.070608 4145.894 0.9997565
times_uncensored_sampled[38]    162.517505   427.424687 3859.376 1.0007154
times_uncensored_sampled[39]    155.596905   427.859781 3911.406 1.0001274
times_uncensored_sampled[40]    161.014202   420.680264 3644.421 0.9995628
times_uncensored_sampled[41]    166.615353   416.072343 3890.390 0.9998858
times_uncensored_sampled[42]    158.689581   435.857625 3701.112 0.9993080
times_uncensored_sampled[43]    153.127521   422.611505 3905.599 1.0018958
times_uncensored_sampled[44]    159.144764   434.028697 4049.115 0.9992360
times_uncensored_sampled[45]    153.324369   408.067409 4137.247 0.9992185
times_uncensored_sampled[46]    158.013746   412.709700 3960.590 1.0017098
times_uncensored_sampled[47]    158.213250   437.005699 4243.139 1.0001253
times_uncensored_sampled[48]    159.737747   400.506624 3952.739 1.0004808
times_uncensored_sampled[49]    161.683176   413.077576 3307.850 1.0004926
times_uncensored_sampled[50]    159.468350   404.803235 3711.188 0.9996495
times_uncensored_sampled[51]    156.954959   419.554978 3357.198 1.0016555
times_uncensored_sampled[52]    161.251528   447.407075 3685.207 1.0000838
times_uncensored_sampled[53]    156.931686   408.424894 3895.026 0.9991541
times_uncensored_sampled[54]    158.319615   421.953452 3956.527 0.9998863
times_uncensored_sampled[55]    156.508808   430.845189 3690.167 0.9998333
times_uncensored_sampled[56]    156.713885   444.425173 3869.293 0.9993080
times_uncensored_sampled[57]    153.413695   414.756300 4273.698 1.0013239
times_uncensored_sampled[58]    162.149492   417.951081 3705.115 1.0009627
times_uncensored_sampled[59]    159.244823   425.299710 4040.428 0.9999408
times_uncensored_sampled[60]    153.998114   421.886335 3957.310 0.9996097
times_uncensored_sampled[61]    156.150197   418.385312 4206.229 1.0008811
times_uncensored_sampled[62]    164.320699   414.766703 3826.107 1.0002396
times_uncensored_sampled[63]    157.916896   416.251239 3540.366 1.0003962
times_uncensored_sampled[64]    155.166883   421.199468 3836.488 1.0004331
times_uncensored_sampled[65]    157.297271   421.399599 4096.311 1.0014714
times_uncensored_sampled[66]    157.337324   424.943574 3932.961 1.0002028
times_uncensored_sampled[67]    160.199226   427.461442 3727.647 0.9995690
times_uncensored_sampled[68]    154.625786   411.755558 3600.718 0.9994482
times_uncensored_sampled[69]    156.422322   405.619438 3802.735 1.0004203
times_uncensored_sampled[70]    161.708415   425.181876 3937.750 1.0001543
times_uncensored_sampled[71]    157.118771   408.063583 3895.273 0.9992953
times_uncensored_sampled[72]    163.773339   420.192794 3898.127 0.9997815
times_uncensored_sampled[73]    159.042114   426.907690 3447.794 1.0010191
times_uncensored_sampled[74]    153.189474   398.692659 3975.104 1.0000231
times_uncensored_sampled[75]    160.961363   419.935461 4162.106 0.9995250
times_uncensored_sampled[76]    159.291137   415.205725 4029.264 1.0003625
times_uncensored_sampled[77]    155.639810   413.788967 4061.340 1.0012144
times_uncensored_sampled[78]    158.527177   423.461965 3720.677 0.9999695
times_uncensored_sampled[79]    156.045800   420.397745 4045.877 1.0003798
times_uncensored_sampled[80]    155.497658   432.719118 3980.304 0.9996282
times_uncensored_sampled[81]    161.746559   438.321115 4104.143 0.9993148
times_uncensored_sampled[82]    162.619374   419.944353 3639.430 1.0003399
times_uncensored_sampled[83]    157.947923   431.269202 3730.146 1.0000390
times_uncensored_sampled[84]    151.703691   413.567411 4035.946 0.9999081
times_uncensored_sampled[85]    163.086731   442.599622 4152.722 0.9996571
times_uncensored_sampled[86]    158.099839   424.710332 4016.970 1.0000976
times_uncensored_sampled[87]    158.670119   415.034147 4243.186 1.0006678
times_uncensored_sampled[88]    158.371560   430.346827 3884.020 0.9995753
times_uncensored_sampled[89]    163.038953   457.431318 4090.477 0.9997118
times_uncensored_sampled[90]    162.170515   417.404612 4103.010 1.0004230
times_uncensored_sampled[91]    164.202215   416.543906 3753.009 1.0000339
times_uncensored_sampled[92]    158.776604   435.544721 3709.424 0.9997599
times_uncensored_sampled[93]    159.722097   417.895148 3892.255 1.0007411
times_uncensored_sampled[94]    158.600093   424.783157 3785.534 0.9995541
times_uncensored_sampled[95]    165.923726   423.822685 3715.454 0.9996369
times_uncensored_sampled[96]    157.158215   416.471579 4078.768 1.0005156
times_uncensored_sampled[97]    155.108564   406.811363 3882.069 1.0003268
times_uncensored_sampled[98]    159.027113   422.238205 4221.782 0.9993589
 [ reached getOption("max.print") -- omitted 547 rows ]
exp_surv_model_draws <- tidybayes::tidy_draws(exp_surv_model_fit)
exp_surv_model_draws
## Constructor for treatment-specific survival function
construct_survival_function <- function(alpha, beta, x) {
    function(t) {
        lambda <- exp(alpha + x*beta)
        exp(-(lambda * t))
    }
}

## Random functions
exp_surv_model_surv_func <-
    exp_surv_model_draws %>%
    select(.chain, .iteration, .draw, alpha, `beta[1]`) %>%
    ## Simplify name
    rename(beta = `beta[1]`) %>%
    ## Construct realization of random functions
    mutate(`S(t|1)` = pmap(list(alpha, beta), function(a,b) {construct_survival_function(a,b,1)}),
           `S(t|0)` = pmap(list(alpha, beta), function(a,b) {construct_survival_function(a,b,0)}))
exp_surv_model_surv_func
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
*** recursive gc invocation
times <- seq(from = 0, to = 165, by = 0.1)
times_df <- data_frame(t = times)

## Try first realizations
exp_surv_model_surv_func$`S(t|1)`[[1]](times[1:10])
 [1] 1.0000000 0.9997758 0.9995516 0.9993274 0.9991033 0.9988793 0.9986553 0.9984313 0.9982074 0.9979836
exp_surv_model_surv_func$`S(t|0)`[[1]](times[1:10])
 [1] 1.0000000 0.9991189 0.9982386 0.9973591 0.9964803 0.9956023 0.9947251 0.9938487 0.9929730 0.9920981
## Apply all realizations
exp_surv_model_survival <-
    exp_surv_model_surv_func %>%
    mutate(times_df = list(times_df)) %>%
    mutate(times_df = pmap(list(times_df, `S(t|1)`, `S(t|0)`),
                           function(df, s1, s0) {df %>% mutate(s1 = s1(t),
                                                               s0 = s0(t))})) %>%
    select(-`S(t|1)`, -`S(t|0)`) %>%
    unnest(cols = c(times_df)) %>%
    gather(key = treatment, value = survival, s1, s0) %>%
    mutate(treatment = factor(treatment, # treatment is whether or not project has more than 20 developers working
                              levels = c("s1","s0"),
                              labels = c("developer count > 20","developer count =< 20")))

## Average on survival scale
exp_surv_model_survival_mean <-
    exp_surv_model_survival %>%
    group_by(treatment, t) %>%
    summarize(survival_mean = mean(survival),
              survival_95upper = quantile(survival, probs = 0.975),
              survival_95lower = quantile(survival, probs = 0.025))
`summarise()` has grouped output by 'treatment'. You can override using the `.groups` argument.
exp_surv_model_survival
# plot the graphs
(ggplot(data = exp_surv_model_survival, mapping = aes(x = t, y = survival, color = treatment, group = interaction(.chain,.draw,treatment))) 
 + geom_line(size = 0.1, alpha = 0.02) 
 + geom_line(data = exp_surv_model_survival_mean, mapping = aes(y = survival_mean, group = treatment)) 
 + geom_line(data = exp_surv_model_survival_mean, mapping = aes(y = survival_95upper, group = treatment), linetype = "dotted") 
 + geom_line(data = exp_surv_model_survival_mean, mapping = aes(y = survival_95lower, group = treatment), linetype = "dotted")
 + scale_color_hue(direction = -1)
 + theme_bw()
 + theme(axis.text.x = element_text(angle = 90, vjust = 0.5), legend.key = element_blank(), plot.title = element_text(hjust = 0.5), strip.background = element_blank()))

LS0tCnRpdGxlOiAiQmF5ZXNpYW4gc3Vydml2YWwgYW5hbHlzaXMgdXNpbmcgYXV0aG9yIGNvdW50IGFzIGEgcHJlZGljdG9yIgpvdXRwdXQ6IGh0bWxfbm90ZWJvb2sKLS0tCmBgYHtyfQpsaWJyYXJ5KHJzdGFuKQpsaWJyYXJ5KHN1cnZpdmFsKQpsaWJyYXJ5KHRpZHl2ZXJzZSkKbGlicmFyeSh0aWR5YmF5ZXMpCmBgYAogCgpgYGB7cn0KIyBkYXRhLCBwYXJhbWV0ZXJzLCBtb2RlbCBhbmQgZ2VuZXJhdGVkIHF1YW50aXRpZXMgYmxvY2tzClN0YW5fZXhwb25lbnRpYWxfc3Vydml2YWxfbW9kZWwgPC0gIgpkYXRhewogIGludCA8bG93ZXI9MT4gTl91bmNlbnNvcmVkOwogIGludCA8bG93ZXI9MT4gTl9jZW5zb3JlZDsKICBpbnQgPGxvd2VyPTA+IG51bUNvdmFyaWF0ZXM7CiAgbWF0cml4W05fY2Vuc29yZWQsIG51bUNvdmFyaWF0ZXNdIFhfY2Vuc29yZWQ7CiAgbWF0cml4W05fdW5jZW5zb3JlZCwgbnVtQ292YXJpYXRlc10gWF91bmNlbnNvcmVkOwogIHZlY3RvciA8bG93ZXI9MD5bTl9jZW5zb3JlZF0gdGltZXNfY2Vuc29yZWQ7CiAgdmVjdG9yIDxsb3dlcj0wPltOX3VuY2Vuc29yZWRdIHRpbWVzX3VuY2Vuc29yZWQ7Cn0KCnBhcmFtZXRlcnN7CiAgdmVjdG9yW251bUNvdmFyaWF0ZXNdIGJldGE7IC8vcmVncmVzc2lvbiBjb2VmZmljaWVudHMKICByZWFsIGFscGhhOyAvL2ludGVyY2VwdAp9Cgptb2RlbHsKICBiZXRhIH4gbm9ybWFsKDAsMTApOyAvL3ByaW9yIG9uIHJlZ3Jlc3Npb24gY29lZmZpY2llbnRzCi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